<?php
namespace Modules\Mallsetting\Database\Seeders;

use Illuminate\Database\Seeder;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Schema;

/**
 * 生成后台商城设置菜单
 * @author RenJianHong
 * @date 2021-08-07 14:46
 */
class MallSettingAuthMenuSeeder extends Seeder
{
    public function run()
    {
        if (Schema::hasTable('auth_menu')){
            $arr = $this->defaultInfo();
            if(!empty($arr) && is_array($arr)) {
                // 删除原来已存在的菜单
                $module = 'mallsetting';
                if($module != ""){
                    DB::table('auth_menu')->where("module", $module)->delete();
                }

                $this->addInfo($arr);
            }
        }
    }

    /**
     * 遍历新增菜单
     * @param array $data
     * @param int $pid
     */
    private function addInfo(array $data, $pid = 0)
    {
        $module = config('mallsetting_config.name') ?? "";
        foreach ($data as $item) {
            $newPid = DB::table('auth_menu')->insertGetId([
                'pid' => $item['pid'] ?? $pid,
                'href' => $item['href'],
                'title' => $item['title'],
                'icon' => $item['icon'],
                'type' => $item['type'],
                'status' => $item['status'],
                'remark' => $item['remark'],
                'target' => $item['target'],
                'sort' => $item['sort'] ?? 99,
                'createtime' => $item['createtime'],
                'module' => $item["module"],
                'menus' => $item["menus"],
            ]);
            if($newPid <= 0) break;
            if(isset($item["contents"]) && is_array($item["contents"]) && !empty($item["contents"])) $this->addInfo($item["contents"], $newPid);
        }
    }

    /**
     * 设置后台管理菜单路由信息
     * @pid 父级
     * @href 路由
     * @title 菜单标题
     * @icon 图标
     * @type int 类型 0 顶级目录 1 目录 2 菜单 3 按钮
     * @status 状态 1 正常 2 停用
     * @remark 备注
     * @target 跳转方式
     * @createtime 创建时间
     */
    private function defaultInfo()
    {
        $module = 'mallsetting';
        $time = time();
        return [
            [
                "pid" => 10004,
                "href" => "",
                "title" => "商城设置",
                "icon" => 'fa fa-gears',
                "type" => 1,
                "status" => 1,
                "remark" => "商城设置",
                "target" => "_self",
                "sort" => 20,
                "createtime" => $time,
                'module' => $module,
                "menus" => $module == "" ? $module : $module . "-1",
                "contents" => [
                    [   //  基础设置
                        "href" => "/admin/mall_setting/setting",
                        "title" => "基础设置",
                        "icon" => 'fa fa-cog',
                        "type" => 2,
                        "status" => 1,
                        "remark" => "基础设置",
                        "target" => "_self",
                        "sort" => 10,
                        "createtime" => $time,
                        'module' => $module,
                        "menus" => $module == "" ? $module : $module . "-2",
                        "contents" => [
                            [
                                "href" => "/admin/mall_setting/setting",
                                "title" => "查看编辑基础设置",
                                "icon" => 'fa fa-window-maximize',
                                "type" => 3,
                                "status" => 1,
                                "remark" => "查看编辑基础设置",
                                "target" => "_self",
                                "sort" => 10,
                                "createtime" => $time,
                                'module' => $module,
                                "menus" => $module == "" ? $module : $module . "-3",
                            ],
                        ],
                    ],
                    [   //  短信通知
                        "href" => "/admin/mall_setting/sms_setting",
                        "title" => "短信通知",
                        "icon" => 'fa fa-bell-o',
                        "type" => 2,
                        "status" => 1,
                        "remark" => "短信通知",
                        "target" => "_self",
                        "sort" => 9,
                        "createtime" => $time,
                        'module' => $module,
                        "menus" => $module == "" ? $module : $module . "-4",
                        "contents" => [
                            [
                                "href" => "/admin/mall_setting/sms_setting",
                                "title" => "查看编辑短信通知",
                                "icon" => 'fa fa-window-maximize',
                                "type" => 3,
                                "status" => 1,
                                "remark" => "查看编辑短信通知",
                                "target" => "_self",
                                "sort" => 10,
                                "createtime" => $time,
                                'module' => $module,
                                "menus" => $module == "" ? $module : $module . "-5",
                            ],
                        ],
                    ],
                    [   //  邮件通知
                        "href" => "/admin/mall_setting/mail_setting",
                        "title" => "邮件通知",
                        "icon" => 'fa fa-bell-o',
                        "type" => 2,
                        "status" => 1,
                        "remark" => "邮件通知",
                        "target" => "_self",
                        "sort" => 8,
                        "createtime" => $time,
                        'module' => $module,
                        "menus" => $module == "" ? $module : $module . "-6",
                        "contents" => [
                            [
                                "href" => "/admin/mall_setting/mail_setting",
                                "title" => "查看编辑邮件通知",
                                "icon" => 'fa fa-window-maximize',
                                "type" => 3,
                                "status" => 1,
                                "remark" => "查看编辑邮件通知",
                                "target" => "_self",
                                "sort" => 10,
                                "createtime" => $time,
                                'module' => $module,
                                "menus" => $module == "" ? $module : $module . "-7",
                            ],
                        ],
                    ],
                    [   //  运费规则
                        "href" => "/admin/postage_rules/list",
                        "title" => "运费规则",
                        "icon" => 'fa fa-truck',
                        "type" => 2,
                        "status" => 1,
                        "remark" => "运费规则",
                        "target" => "_self",
                        "sort" => 7,
                        "createtime" => $time,
                        'module' => $module,
                        "menus" => $module == "" ? $module : $module . "-8",
                        "contents" => [
                            [
                                "href" => "/admin/postage_rules/list",
                                "title" => "查看运费规则列表",
                                "icon" => 'fa fa-window-maximize',
                                "type" => 3,
                                "status" => 1,
                                "remark" => "查看运费规则列表",
                                "target" => "_self",
                                "sort" => 10,
                                "createtime" => $time,
                                'module' => $module,
                                "menus" => $module == "" ? $module : $module . "-9",
                            ],
                            [
                                "href" => "/admin/postage_rules/ajaxList",
                                "title" => "异步获取运费规则列表数据",
                                "icon" => 'fa fa-window-maximize',
                                "type" => 3,
                                "status" => 1,
                                "remark" => "异步获取运费规则列表数据",
                                "target" => "_self",
                                "sort" => 10,
                                "createtime" => $time,
                                'module' => $module,
                                "menus" => $module == "" ? $module : $module . "-10",
                            ],
                            [
                                "href" => "/admin/postage_rules/edit",
                                "title" => "新增编辑运费规则",
                                "icon" => 'fa fa-window-maximize',
                                "type" => 3,
                                "status" => 1,
                                "remark" => "新增编辑运费规则",
                                "target" => "_self",
                                "sort" => 10,
                                "createtime" => $time,
                                'module' => $module,
                                "menus" => $module == "" ? $module : $module . "-11",
                            ],
                            [
                                "href" => "/admin/postage_rules/delete",
                                "title" => "删除运费规则",
                                "icon" => 'fa fa-window-maximize',
                                "type" => 3,
                                "status" => 1,
                                "remark" => "删除运费规则",
                                "target" => "_self",
                                "sort" => 10,
                                "createtime" => $time,
                                'module' => $module,
                                "menus" => $module == "" ? $module : $module . "-12",
                            ],
                            [
                                "href" => "/admin/postage_rules/batchDelete",
                                "title" => "批量删除运费规则",
                                "icon" => 'fa fa-window-maximize',
                                "type" => 3,
                                "status" => 1,
                                "remark" => "批量删除运费规则",
                                "target" => "_self",
                                "sort" => 10,
                                "createtime" => $time,
                                'module' => $module,
                                "menus" => $module == "" ? $module : $module . "-13",
                            ],
                            [
                                "href" => "/admin/postage_rules/isDefault",
                                "title" => "设置默认运费规则",
                                "icon" => 'fa fa-window-maximize',
                                "type" => 3,
                                "status" => 1,
                                "remark" => "设置默认运费规则",
                                "target" => "_self",
                                "sort" => 10,
                                "createtime" => $time,
                                'module' => $module,
                                "menus" => $module == "" ? $module : $module . "-14",
                            ],
                            [
                                "href" => "/admin/postage_rules/getArea",
                                "title" => "获取省份区域",
                                "icon" => 'fa fa-window-maximize',
                                "type" => 3,
                                "status" => 1,
                                "remark" => "获取省份区域",
                                "target" => "_self",
                                "sort" => 10,
                                "createtime" => $time,
                                'module' => $module,
                                "menus" => $module == "" ? $module : $module . "-15",
                            ],
                        ],
                    ],
                    [   //  包邮规则
                        "href" => "/admin/free_delivery_rules/list",
                        "title" => "包邮规则",
                        "icon" => 'fa fa-truck',
                        "type" => 2,
                        "status" => 1,
                        "remark" => "包邮规则",
                        "target" => "_self",
                        "sort" => 6,
                        "createtime" => $time,
                        'module' => $module,
                        "menus" => $module == "" ? $module : $module . "-16",
                        "contents" => [
                            [
                                "href" => "/admin/free_delivery_rules/list",
                                "title" => "查看包邮规则列表",
                                "icon" => 'fa fa-window-maximize',
                                "type" => 3,
                                "status" => 1,
                                "remark" => "查看包邮规则列表",
                                "target" => "_self",
                                "sort" => 10,
                                "createtime" => $time,
                                'module' => $module,
                                "menus" => $module == "" ? $module : $module . "-17",
                            ],
                            [
                                "href" => "/admin/free_delivery_rules/ajaxList",
                                "title" => "异步获取包邮规则列表数据",
                                "icon" => 'fa fa-window-maximize',
                                "type" => 3,
                                "status" => 1,
                                "remark" => "异步获取包邮规则列表数据",
                                "target" => "_self",
                                "sort" => 10,
                                "createtime" => $time,
                                'module' => $module,
                                "menus" => $module == "" ? $module : $module . "-18",
                            ],
                            [
                                "href" => "/admin/free_delivery_rules/edit",
                                "title" => "新增编辑包邮规则",
                                "icon" => 'fa fa-window-maximize',
                                "type" => 3,
                                "status" => 1,
                                "remark" => "新增编辑包邮规则",
                                "target" => "_self",
                                "sort" => 10,
                                "createtime" => $time,
                                'module' => $module,
                                "menus" => $module == "" ? $module : $module . "-19",
                            ],
                            [
                                "href" => "/admin/free_delivery_rules/delete",
                                "title" => "删除包邮规则",
                                "icon" => 'fa fa-window-maximize',
                                "type" => 3,
                                "status" => 1,
                                "remark" => "删除包邮规则",
                                "target" => "_self",
                                "sort" => 10,
                                "createtime" => $time,
                                'module' => $module,
                                "menus" => $module == "" ? $module : $module . "-20",
                            ],
                            [
                                "href" => "/admin/free_delivery_rules/batchDelete",
                                "title" => "批量删除包邮规则",
                                "icon" => 'fa fa-window-maximize',
                                "type" => 3,
                                "status" => 1,
                                "remark" => "批量删除包邮规则",
                                "target" => "_self",
                                "sort" => 10,
                                "createtime" => $time,
                                'module' => $module,
                                "menus" => $module == "" ? $module : $module . "-21",
                            ],
                            [
                                "href" => "/admin/free_delivery_rules/getArea",
                                "title" => "获取省份区域",
                                "icon" => 'fa fa-window-maximize',
                                "type" => 3,
                                "status" => 1,
                                "remark" => "获取省份区域",
                                "target" => "_self",
                                "sort" => 10,
                                "createtime" => $time,
                                'module' => $module,
                                "menus" => $module == "" ? $module : $module . "-22",
                            ],
                        ],
                    ],
                    [   //  区域限制购买规则
                        "href" => "/admin/mall_setting/territorial_limitation",
                        "title" => "区域限制购买",
                        "icon" => 'fa fa-slack',
                        "type" => 2,
                        "status" => 1,
                        "remark" => "区域限制购买",
                        "target" => "_self",
                        "sort" => 5,
                        "createtime" => $time,
                        'module' => $module,
                        "menus" => $module == "" ? $module : $module . "-23",
                        "contents" => [
                            [
                                "href" => "/admin/mall_setting/territorial_limitation",
                                "title" => "查看编辑区域限制购买",
                                "icon" => 'fa fa-window-maximize',
                                "type" => 3,
                                "status" => 1,
                                "remark" => "查看区域限制购买规则",
                                "target" => "_self",
                                "sort" => 10,
                                "createtime" => $time,
                                'module' => $module,
                                "menus" => $module == "" ? $module : $module . "-24",
                            ],
                            [
                                "href" => "/admin/mall_setting/getArea",
                                "title" => "获取省市区区域",
                                "icon" => 'fa fa-window-maximize',
                                "type" => 3,
                                "status" => 1,
                                "remark" => "获取省市区区域",
                                "target" => "_self",
                                "sort" => 10,
                                "createtime" => $time,
                                'module' => $module,
                                "menus" => $module == "" ? $module : $module . "-25",
                            ],
                        ],
                    ],
                    [   //  起送规则
                        "href" => "/admin/mall_setting/offer_price",
                        "title" => "起送规则",
                        "icon" => 'fa fa-motorcycle',
                        "type" => 2,
                        "status" => 1,
                        "remark" => "起送规则",
                        "target" => "_self",
                        "sort" => 4,
                        "createtime" => $time,
                        'module' => $module,
                        "menus" => $module == "" ? $module : $module . "-26",
                        "contents" => [
                            [
                                "href" => "/admin/mall_setting/offer_price",
                                "title" => "查看编辑起送规则",
                                "icon" => 'fa fa-window-maximize',
                                "type" => 3,
                                "status" => 1,
                                "remark" => "查看编辑起送规则",
                                "target" => "_self",
                                "sort" => 10,
                                "createtime" => $time,
                                'module' => $module,
                                "menus" => $module == "" ? $module : $module . "-27",
                            ],
                        ],
                    ],
                    [   //  退货地址
                        "href" => "/admin/refund_address/list",
                        "title" => "退货地址",
                        "icon" => 'fa fa-map-marker',
                        "type" => 2,
                        "status" => 1,
                        "remark" => "退货地址",
                        "target" => "_self",
                        "sort" => 3,
                        "createtime" => $time,
                        'module' => $module,
                        "menus" => $module == "" ? $module : $module . "-28",
                        "contents" => [
                            [
                                "href" => "/admin/refund_address/list",
                                "title" => "查看退货地址列表",
                                "icon" => 'fa fa-window-maximize',
                                "type" => 3,
                                "status" => 1,
                                "remark" => "查看退货地址列表",
                                "target" => "_self",
                                "sort" => 10,
                                "createtime" => $time,
                                'module' => $module,
                                "menus" => $module == "" ? $module : $module . "-29",
                            ],
                            [
                                "href" => "/admin/refund_address/ajaxList",
                                "title" => "异步获取退货地址列表数据",
                                "icon" => 'fa fa-window-maximize',
                                "type" => 3,
                                "status" => 1,
                                "remark" => "异步获取退货地址列表数据",
                                "target" => "_self",
                                "sort" => 10,
                                "createtime" => $time,
                                'module' => $module,
                                "menus" => $module == "" ? $module : $module . "-30",
                            ],
                            [
                                "href" => "/admin/refund_address/edit",
                                "title" => "新增编辑退货地址",
                                "icon" => 'fa fa-window-maximize',
                                "type" => 3,
                                "status" => 1,
                                "remark" => "新增编辑退货地址",
                                "target" => "_self",
                                "sort" => 10,
                                "createtime" => $time,
                                'module' => $module,
                                "menus" => $module == "" ? $module : $module . "-31",
                            ],
                            [
                                "href" => "/admin/refund_address/delete",
                                "title" => "删除退货地址",
                                "icon" => 'fa fa-window-maximize',
                                "type" => 3,
                                "status" => 1,
                                "remark" => "删除退货地址",
                                "target" => "_self",
                                "sort" => 10,
                                "createtime" => $time,
                                'module' => $module,
                                "menus" => $module == "" ? $module : $module . "-32",
                            ],
                            [
                                "href" => "/admin/refund_address/batchDelete",
                                "title" => "批量删除退货地址",
                                "icon" => 'fa fa-window-maximize',
                                "type" => 3,
                                "status" => 1,
                                "remark" => "批量删除退货地址",
                                "target" => "_self",
                                "sort" => 10,
                                "createtime" => $time,
                                'module' => $module,
                                "menus" => $module == "" ? $module : $module . "-33",
                            ],
                        ],
                    ],
                    
                ],
            ],
        ];
    }
}